package com.zcxx.cotton.base;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zcxx.cotton.base.domain.MembraneReturn;
import com.zcxx.cotton.base.service.IMembraneReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 膜退回Controller
 *
 * @author ruoyi
 * @date 2025-09-18
 */
@RestController
@RequestMapping("/membrane/return")
public class MembraneReturnController extends BaseController
{
    @Autowired
    private IMembraneReturnService membraneReturnService;

    /**
     * 查询膜退回列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MembraneReturn membraneReturn) {
        startPage();
        List<MembraneReturn> list = membraneReturnService.selectMembraneReturnList(membraneReturn);
        return getDataTable(list);
    }

    /**
     * 导出膜退回列表
     */
    @Log(title = "膜退回", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MembraneReturn membraneReturn) {
        List<MembraneReturn> list = membraneReturnService.selectMembraneReturnList(membraneReturn);
        ExcelUtil<MembraneReturn> util = new ExcelUtil<MembraneReturn>(MembraneReturn.class);
        util.exportExcel(response, list, "膜退回数据");
    }

    /**
     * 获取膜退回详细信息
     */
    @GetMapping(value = "/{returnId}")
    public AjaxResult getInfo(@PathVariable("returnId") Long returnId) {
        return success(membraneReturnService.getById(returnId));
    }


    /**
     * 新增或者修改膜退回
     */
    @PostMapping("/addUpdateMembraneReturn")
    public AjaxResult addUpdateMembraneReturn(@RequestBody MembraneReturn membraneReturn) {
        if(membraneReturn.getReturnId()==null){ //新增
            return toAjax(membraneReturnService.save(membraneReturn));
        }
        return toAjax(membraneReturnService.updateById(membraneReturn));
    }


    /**
     * 删除膜退回
     */
    @Log(title = "膜退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{returnIds}")
    public AjaxResult remove(@PathVariable Long[] returnIds) {
        return toAjax(membraneReturnService.removeBatchByIds(Arrays.asList(returnIds)));
    }
}
